home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Magazine / GraphicsCards / StormMesa / src / pb.h < prev    next >
C/C++ Source or Header  |  1999-02-04  |  4KB  |  169 lines

  1. /* $Id: pb.h,v 3.1 1998/03/05 02:59:05 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  3.0
  6.  * Copyright (C) 1995-1998  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: pb.h,v $
  26.  * Revision 3.1  1998/03/05 02:59:05  brianp
  27.  * [RGBA]COMP wasn't being used in a few places
  28.  *
  29.  * Revision 3.0  1998/01/31 21:00:28  brianp
  30.  * initial rev
  31.  *
  32.  */
  33.  
  34.  
  35. #ifndef PB_H
  36. #define PB_H
  37.  
  38.  
  39. #include "types.h"
  40.  
  41.  
  42.  
  43. /*
  44.  * Pixel buffer size, must be larger than MAX_WIDTH.
  45.  */
  46. #define PB_SIZE (3*MAX_WIDTH)
  47.  
  48.  
  49. struct pixel_buffer {
  50.     GLint x[PB_SIZE];    /* X window coord in [0,MAX_WIDTH) */
  51.     GLint y[PB_SIZE];    /* Y window coord in [0,MAX_HEIGHT) */
  52.     GLdepth z[PB_SIZE];    /* Z window coord in [0,MAX_DEPTH] */
  53.     GLubyte rgba[PB_SIZE][4];/* Colors */
  54.     GLuint i[PB_SIZE];    /* Index */
  55.     GLfloat s[PB_SIZE];    /* Texture S coordinate */
  56.     GLfloat t[PB_SIZE];    /* Texture T coordinate */
  57.     GLfloat u[PB_SIZE];    /* Texture R coordinate */
  58.     GLfloat lambda[PB_SIZE];/* Texture lambda values */
  59.     GLint color[4];        /* Mono color, integers! */
  60.     GLuint index;        /* Mono index */
  61.     GLuint count;        /* Number of pixels in buffer */
  62.     GLboolean mono;        /* Same color or index for all pixels? */
  63.     GLenum primitive;    /* GL_POINT, GL_LINE, GL_POLYGON or GL_BITMAP*/
  64. };
  65.  
  66.  
  67. /*
  68.  * Initialize the Pixel Buffer, specifying the type of primitive being drawn.
  69.  */
  70. #define PB_INIT( PB, PRIM )        \
  71.     (PB)->count = 0;        \
  72.     (PB)->mono = GL_FALSE;        \
  73.     (PB)->primitive = (PRIM);
  74.  
  75.  
  76.  
  77. /*
  78.  * Set the color used for all subsequent pixels in the buffer.
  79.  */
  80. #define PB_SET_COLOR( CTX, PB, R, G, B, A )            \
  81.     if ((PB)->color[RCOMP]!=(R) || (PB)->color[GCOMP]!=(G)    \
  82.      || (PB)->color[BCOMP]!=(B) || (PB)->color[ACOMP]!=(A)    \
  83.      || !(PB)->mono) {                    \
  84.         gl_flush_pb( ctx );                \
  85.     }                                \
  86.     (PB)->color[RCOMP] = R;                    \
  87.     (PB)->color[GCOMP] = G;                    \
  88.     (PB)->color[BCOMP] = B;                    \
  89.     (PB)->color[ACOMP] = A;                    \
  90.     (PB)->mono = GL_TRUE;
  91.  
  92.  
  93. /*
  94.  * Set the color index used for all subsequent pixels in the buffer.
  95.  */
  96. #define PB_SET_INDEX( CTX, PB, I )        \
  97.     if ((PB)->index!=(I) || !(PB)->mono) {    \
  98.         gl_flush_pb( CTX );        \
  99.     }                    \
  100.     (PB)->index = I;            \
  101.     (PB)->mono = GL_TRUE;
  102.  
  103.  
  104. /*
  105.  * "write" a pixel using current color or index
  106.  */
  107. #define PB_WRITE_PIXEL( PB, X, Y, Z )        \
  108.     (PB)->x[(PB)->count] = X;        \
  109.     (PB)->y[(PB)->count] = Y;        \
  110.     (PB)->z[(PB)->count] = Z;        \
  111.     (PB)->count++;
  112.  
  113.  
  114. /*
  115.  * "write" an RGBA pixel
  116.  */
  117. #define PB_WRITE_RGBA_PIXEL( PB, X, Y, Z, R, G, B, A )    \
  118.     (PB)->x[(PB)->count] = X;            \
  119.     (PB)->y[(PB)->count] = Y;            \
  120.     (PB)->z[(PB)->count] = Z;            \
  121.     (PB)->rgba[(PB)->count][RCOMP] = R;        \
  122.     (PB)->rgba[(PB)->count][GCOMP] = G;        \
  123.     (PB)->rgba[(PB)->count][BCOMP] = B;        \
  124.     (PB)->rgba[(PB)->count][ACOMP] = A;        \
  125.     (PB)->count++;
  126.  
  127. /*
  128.  * "write" a color-index pixel
  129.  */
  130. #define PB_WRITE_CI_PIXEL( PB, X, Y, Z, I )    \
  131.     (PB)->x[(PB)->count] = X;        \
  132.     (PB)->y[(PB)->count] = Y;        \
  133.     (PB)->z[(PB)->count] = Z;        \
  134.     (PB)->i[(PB)->count] = I;        \
  135.     (PB)->count++;
  136.  
  137.  
  138. /*
  139.  * "write" an RGBA pixel with texture coordinates
  140.  */
  141. #define PB_WRITE_TEX_PIXEL( PB, X, Y, Z, R, G, B, A, S, T, U )    \
  142.     (PB)->x[(PB)->count] = X;                \
  143.     (PB)->y[(PB)->count] = Y;                \
  144.     (PB)->z[(PB)->count] = Z;                \
  145.     (PB)->rgba[(PB)->count][RCOMP] = R;            \
  146.     (PB)->rgba[(PB)->count][GCOMP] = G;            \
  147.     (PB)->rgba[(PB)->count][BCOMP] = B;            \
  148.     (PB)->rgba[(PB)->count][ACOMP] = A;            \
  149.     (PB)->s[(PB)->count] = S;                \
  150.     (PB)->t[(PB)->count] = T;                \
  151.     (PB)->u[(PB)->count] = U;                \
  152.     (PB)->count++;
  153.  
  154.  
  155. /*
  156.  * Call this function at least every MAX_WIDTH pixels:
  157.  */
  158. #define PB_CHECK_FLUSH( CTX, PB )        \
  159.     if ((PB)->count>=PB_SIZE-MAX_WIDTH) {    \
  160.        gl_flush_pb( CTX );            \
  161.     }
  162.  
  163.  
  164. extern struct pixel_buffer *gl_alloc_pb(void);
  165.  
  166. extern void gl_flush_pb( GLcontext *ctx );
  167.  
  168. #endif
  169.